package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatGodLevel;
import com.happy.cat.project.system.service.ICatGodLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 大神等级Controller
 *
 * @author verne
 * @date 2020-07-17
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/level" )
@Api("大神等级 API")
public class CatGodLevelController extends BaseController {

    private final ICatGodLevelService iCatGodLevelService;

    /**
     * 查询大神等级列表
     */
    @ApiOperation(value = "查询大神等级列表",notes = "查询大神等级列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:level:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatGodLevel catGodLevel)
    {
        startPage();
        LambdaQueryWrapper<CatGodLevel> lqw = new LambdaQueryWrapper<CatGodLevel>();
        if (StringUtils.isNotBlank(catGodLevel.getGodIcon())){
            lqw.eq(CatGodLevel::getGodIcon ,catGodLevel.getGodIcon());
        }
        if (catGodLevel.getOrders() != null){
            lqw.eq(CatGodLevel::getOrders ,catGodLevel.getOrders());
        }
        if (catGodLevel.getPositive() != null){
            lqw.eq(CatGodLevel::getPositive ,catGodLevel.getPositive());
        }
        if (catGodLevel.getStatus() != null){
            lqw.eq(CatGodLevel::getStatus ,catGodLevel.getStatus());
        }
        List<CatGodLevel> list = iCatGodLevelService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出大神等级列表
     */
    @ApiOperation(value = "导出大神等级列表",notes = "导出大神等级列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:level:export')" )
    @Log(title = "大神等级" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatGodLevel catGodLevel) {
        LambdaQueryWrapper<CatGodLevel> lqw = new LambdaQueryWrapper<CatGodLevel>(catGodLevel);
        List<CatGodLevel> list = iCatGodLevelService.list(lqw);
        ExcelUtil<CatGodLevel> util = new ExcelUtil<CatGodLevel>(CatGodLevel. class);
        return util.exportExcel(list, "level" );
    }

    @GetMapping(value = "/all" )
    public AjaxResult load() {
        return AjaxResult.success(iCatGodLevelService.list());
    }


    /**
     * 获取大神等级详细信息
     */
    @ApiOperation(value = "获取大神等级详细信息",notes = "获取大神等级详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:level:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatGodLevelService.getById(id));
    }

    /**
     * 新增大神等级
     */
    @ApiOperation(value = "新增大神等级",notes = "新增大神等级",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:level:add')" )
    @Log(title = "大神等级" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatGodLevel catGodLevel) {
        catGodLevel.setCreateTime(new Date());
        catGodLevel.setUpdateTime(new Date());
        catGodLevel.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatGodLevelService.save(catGodLevel) ? 1 : 0);
    }

    /**
     * 修改大神等级
     */
    @ApiOperation(value = "修改大神等级",notes = "修改大神等级",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:level:edit')" )
    @Log(title = "大神等级" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatGodLevel catGodLevel) {
        catGodLevel.setUpdateTime(new Date());
        return toAjax(iCatGodLevelService.updateById(catGodLevel) ? 1 : 0);
    }

    /**
     * 删除大神等级
     */
    @ApiOperation(value = "删除大神等级",notes = "删除大神等级",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:level:remove')" )
    @Log(title = "大神等级" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatGodLevelService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
